package org.apache.servicecomb.samples.practise.houserush.sale.aggregate;

import lombok.Data;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: Snake Man
 * @system:
 * @DateTime: 2022/1/18 12:55
 * @Description:
 */
@Data
@Entity
@Table(name = "house_orders")
@EntityListeners(AuditingEntityListener.class)
public class HouseOrder {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    //房源订单和活动是多对一
    @ManyToOne
    @JoinColumn(name = "sale_id")
    private Sale sale;

    private Integer customerId;

    private String state = "new";

    private Integer houseId;

    @Temporal(TemporalType.TIMESTAMP)
    private Date orderedAt;

    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date CreatedAt;

    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date UpdatedAt;

    //房源名称
    @Transient
    private String houseName;
    //房源价格
    @Transient
    private BigDecimal price;
    //楼栋名称
    @Transient
    private String builDingName;
    //楼盘名称
    @Transient
    private String realestateName;
    //用户名称
    @Transient
    private String name;
    //用户电话
    @Transient
    private String phone;

    @OneToMany(mappedBy = "houseOrder")
    @Fetch(FetchMode.JOIN)
    private List<Favorite> favorites = new ArrayList<>();

    //按照客户id查询时，表名房源订单该客户是否收藏
    @Transient
    private String favorite;
}
